package web.dropwizard.healthCheck;

import com.codahale.metrics.health.HealthCheck;
import util.mongodb.MongoDBDataSource;

/**
 * @author Gregory Boissinot
 */
public class MongoHealthCheck extends HealthCheck {

    private final MongoDBDataSource mongoDBDataSource;

    public MongoHealthCheck(MongoDBDataSource mongoDBDataSource) {
        this.mongoDBDataSource = mongoDBDataSource;
    }

    @Override
    protected Result check() throws Exception {
        mongoDBDataSource.getMongo().getDatabaseNames();
        return Result.healthy("Connection to databases OK.");
    }
}
